<?php 
	/* pChart library inclusions */
	include_once("class/pData.class.php");
	include_once("class/pDraw.class.php");
	include_once("class/pPie.class.php");
	include_once("class/pImage.class.php");

	define("DEFAULT_PIE_RADIUS", "110");
	define("DEFAULT_LABEL_LEFT", "15");
	define("DEFAULT_PIE_TOP", "200");
	define("DEFAULT_TITLE_BAR_HEIGHT", "30");
	
function drawPie($values, $labels, $width, $height, $pieRadius, $labelLeft, $pieTop, $titleBarHeight, $title) {	
	
	$filteredValues = array();
	$filteredNames = array();
	
	foreach ($values as $i => $value) {
		if ($value != 0) {
			$filteredValues[] = $value;
			$filteredNames[] = $labels[$i];
		}
	}
	
	/* Create and populate the pData object */
	$MyData = new pData();   
	$MyData->addPoints($filteredValues,"ScoreA");  
	$MyData->setSerieDescription("ScoreA","Application A");
	
	/* Define the absissa serie */
	$MyData->addPoints($filteredNames,"Labels");
	$MyData->setAbscissa("Labels");
	
	$estimatedLabelsSize = 178 + $labelLeft;	 
	$remainingWidth = $width - $estimatedLabelsSize; 
	$pieLeft = ($remainingWidth / 2) - ($pieRadius / 2) + $estimatedLabelsSize;
	$labelTop = $titleBarHeight + 15;
	 
	/* Create the pChart object */
	$myPicture = new pImage($width,$height,$MyData);
	
	/* Draw a solid background */
	$Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
	$myPicture->drawFilledRectangle(0,0,$width,$height,$Settings);
	
	/* Overlay with a gradient */
	$Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
	$myPicture->drawGradientArea(0,0,$width,$height,DIRECTION_VERTICAL,$Settings);
	$myPicture->drawGradientArea(0,0,$width,$titleBarHeight,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>100));
	
	/* Add a border to the picture */
	$myPicture->drawRectangle(0,0,$width - 1, $height - 1,array("R"=>0,"G"=>0,"B"=>0));
	
	/* Write the picture title */ 
	$myPicture->setFontProperties(array("FontName"=>"../fonts/HelveticaNeue-Bold.ttf","FontSize"=>10));
	$myPicture->drawText(10,22,$title,array("R"=>255,"G"=>255,"B"=>255));
	
	/* Set the default font properties */ 
	$myPicture->setFontProperties(array("FontName"=>"../fonts/HelveticaNeue.ttf","FontSize"=>9,"R"=>80,"G"=>80,"B"=>80));
	
	/* Create the pPie object */ 
	$PieChart = new pPie($myPicture,$MyData);
	
	/* Draw an AA pie chart */ 
	$PieChart->draw3DPie($pieLeft, $pieTop,array("Radius"=> $pieRadius,"DrawLabels"=>TRUE,"LabelStacked"=>TRUE,"Border"=>TRUE));
	
	/* Write the legend box */ 
	$myPicture->setShadow(FALSE);
	$PieChart->drawPieLegend($labelLeft,$labelTop,array("Alpha"=>20));
	
	/* Render the picture (choose the best way) */
	$myPicture->autoOutput("pictures/example.draw3DPie.labels.png");
}
?>
